package com.mdc;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by Mordecai on 2017/9/24
 */
@WebServlet(
        name = "MyOwnServlet",
        description = "This is my first annotated servlet",
        urlPatterns = {"/a"})
public class MyServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req,
                         HttpServletResponse resp)
            throws ServletException, IOException {
        System.out.println("MyServlet.doGet() is called.");
        resp.getWriter().write("<h1>MyServlet access successfully!</h1>");
        //super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req,
                          HttpServletResponse resp)
            throws ServletException, IOException {
        System.out.println("MyServlet.doPost() is called.");
        resp.setContentType("text/html");
        PrintWriter out = resp.getWriter();
        out.println("<h1>MyServlet</h1>");
        //super.doPost(req, resp);
    }
}
